package mediatheque.model;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Date;

public class PeriodiqueModel extends DocumentModel {
	
	private static final long serialVersionUID = 2397569780136202682L;

	private String periodicite;
	
	private static int NOMBRE_PERIODIQUES = 0;
	
	public PeriodiqueModel() {
		this("N/A","N/A","N/A",new Date(),"N/A",true,null);
	}
	
	public PeriodiqueModel(String periodicite,  
			String nom,String etat, Date dateAjout, String description,
			boolean empruntable, ArrayList<String> listeTheme) {
		
		super("Periodique", nom,etat, description, empruntable, listeTheme);
		
		this.periodicite = periodicite;
		
		NOMBRE_PERIODIQUES++;
		this.setIdentifiant(genererIdentifiant());
	}
	
	private String genererIdentifiant() {
		return "PE-" + NOMBRE_PERIODIQUES;
	}

	public String getPeriodicite() {
		return periodicite;
	}
	
	public void setPeriodicite(String periodicite) {
		this.periodicite = periodicite;
	}
	
	private void writeObject(ObjectOutputStream oos) throws IOException {
		oos.defaultWriteObject();
		oos.writeObject(new Integer(NOMBRE_PERIODIQUES));
	}

	private void readObject(ObjectInputStream ois)
			throws ClassNotFoundException, IOException {
		ois.defaultReadObject();
		NOMBRE_PERIODIQUES = (Integer) ois.readObject();
	}

}
